<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/14
  Time: 9:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title>添加门禁卡信息</title>
</head>
<body>
    <form action="CardAdd" method="post">
        <table border="1px" align="center" width="400px">
            <tr>
                <td colspan="2"><h2>添加门禁卡信息</h2></td>
            </tr>
            <tr>
                <td>持卡人姓名(*)</td>
                <td><input type="text" id="username" name="username"></td>
            </tr>
            <tr>
                <td>持卡人身份证号(*)</td>
                <td><input type="text" id="idNumber" name="idNumber"></td>
            </tr>
            <tr>
                <td>办卡日期(*)</td>
                <td><input type="text" id="createDate" name="createDate"><br><span id="span"></span></td>
            </tr>
            <tr align="center">
                <td colspan="2"><input type="submit"></td>
            </tr>
        </table>
    </form>
</body>
<script src="jq/jquery.js"></script>
<script>
    $('form').submit(function () {
        var flag=true;
        if(!CheckUserName()) flag=false;
        else if(!CheckIdNumber()) flag=false;
        else if(!CheckCreateDate()) flag=false;
        return flag;
    })
    
    function CheckUserName() {
        if($('#username').val()==""){
            alert("请填写完整的门禁卡信息！")
            return false;
        }
        return true;
    }
    function CheckIdNumber() {
        var idNumber = $("#idNumber").val();
        if(idNumber==""){
            alert("请填写完整的门禁卡信息！")
            return false;
        }else{
            $.getJSON(
                "CardIdNumber",
                {idNumber:idNumber},
                function (data) {
                }
            )
        }
        return true;
    }
    function CheckCreateDate() {
        var idNumber = $("#idNumber").val();
        var createDate = $('#createDate').val()
        var dateFormat =/^(\d{4})-(\d{2})-(\d{2})$/;
        var span = $("#span").val();
        if(createDate==""){
            alert("请填写完整的门禁卡信息！")
            return false;
        }else if(dateFormat.test(createDate) == false){
            alert("日期格式不正确")
            return false;
        }
        return true;
    }
</script>
</html>
